package com.jy.adscm.declarationForm.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.annotation.AdscmLogger;
import com.jy.adscm.declarationForm.bean.JyDeclarationForm;
import com.jy.adscm.declarationForm.bean.JyFormTermManage;
import com.jy.adscm.declarationForm.service.JyFormTermManageService;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.support.SimpleCoreResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 报单的过程记录期限管理 前端控制器
 * </p>
 *
 * @author yyy
 * @since 2019-01-26
 */
@RestController
@RequestMapping("/adscm/dealer/jyFormTermManage")
public class JyFormTermManageController {


    @Autowired
    JyFormTermManageService jyFormTermManageService;

    /**
     * 查询某个报单记录的期限信息
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/queryFormTerm/{formId}")
    @AdscmLogger("查询某个报单记录的期限信息")
    public SimpleCoreResponse queryFormTerm(@PathVariable Integer formId) throws AdscmSystemException {

        Wrapper<JyFormTermManage> wrapper = new EntityWrapper<>();
        wrapper.eq("form_id",formId);
        JyFormTermManage manage = jyFormTermManageService.selectOne(wrapper);

        String resultDesc = "";
        String resultStatus = "300";
        if (manage != null){
            Integer formStatus = manage.getFormStatus();

            if (formStatus == 0){
                resultStatus = "200";
                resultDesc = "总共期限：【"+manage.getTotalTerm()+"】天，剩余：【"+manage.getSurplusTerm()+"】天！";
            }else if (formStatus == 1){
                resultStatus = "200";
                resultDesc = "已经在期限内完成过程记录填报！";
            }else {
                resultStatus = "200";
                resultDesc = "已经过期，报单已经废弃！";
            }
        }

        return new SimpleCoreResponse(resultStatus,resultDesc,null);
    }
}

